﻿$(function () {
    $("#forgotsubmit").click(function () {
        SubmitForgot();
    });

    $("#form").keypress(function (event) {
        if (event.which == '13') {
            SubmitForgot();
        }
    });

    $("#captcharefresh").click(function () {
        var randomnumber = Math.floor(Math.random() * 9999999)
        $("#captcha").attr("src", "/Security/Captcha?r=" + randomnumber);
    });
});

function SubmitForgot() {

    $("#forgotsubmit").hide();

    var input = {
        Email: $("#ForgotEmail").val(),
        Captcha: $("#Captcha").val()
    };

    Ajax({
        url: "/Security/TryForgot",
        data: JSON.stringify(input),
        success: function (data) {
            if (data.IsValid == true) {
                location.href = "/Security/ForgotComplete";
            } else {
                ShowValidationErrors(data, { "Email": "ForgotEmail" });
            }
        },
        complete: function () {
            $("#forgotsubmit").show();
        }
    });
}